﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Srvtools;

public partial class WorkTimeN_WorkTimeOut : System.Web.UI.Page
{
    #region 系统

    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            if (Request["id"] != null)
            {
                InitializeComponent(true);
           
                FLWebNavigator1.Visible = true;
                Master.DataSource = WMaster;
                WMaster.SetWhere("OutId=" + Request["id"].ToString());

                 string FlowFlag = Request["FlowFlag"].ToString();
                 string EmployeeId = Request["EmpId"].ToString();
                 if (FlowFlag == "" && Convert.ToInt32("0" + EmployeeId) == Convert.ToInt32(Srvtools.CliUtils.fLoginUser))
                 {
                 }
                 else
                 {
                     object o = FLWebNavigator1.NavControls["Comment"];
                    // FLWebNavigator1.NavControls.Clear();
                     FLWebNavigator1.NavControls.Add(o);
                 }

                DataSet ds = WMaster.Execute("SELECT SYS_TODOLIST.LISTID FROM SYS_TODOLIST WHERE  SYS_TODOLIST.FORM_TABLE='WorkTime_Out'" +
                    " and SYS_TODOLIST.FORM_KEYS='OutId' and  SYS_TODOLIST.FORM_PRESENTATION='OutId=" + Request["id"].ToString() + "'");
                if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                    ImageButton imb = new ImageButton();
                    imb.ImageUrl = "../image/uipics/Comment_C.gif";
                    imb.ID = "i";
                    imb.Attributes.Add("onclick", "window.open('../InnerPages/FlowComment.aspx?LISTID=" + ds.Tables[0].Rows[0][0].ToString()
                        + "&ATTACHMENTS=', '', 'resizable=yes,scrollbars=yes,width=645,height=400,top=100,left=200');return false");
                    FLWebNavigator1.Controls.Add(imb);
                }
            }
            else
            {
                InitializeComponent(false);
                Master.DataSource = WMaster;
            }



            MasterPage_MasterPage mpg = (MasterPage_MasterPage)this.Page.Master;
            mpg.HelpHref = "~/Help/WorkTime/公出申请流程.htm";
            mpg.PageName = "公出申请";
            mpg.PicUrl = "";
            mpg.IntiBar();
        }
    }

    private void InitializeComponent(bool action)
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WorkTimeN_WorkTimeOut));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = action;
        this.WMaster.AlwaysClose = true;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "SWorkTime.WorkTime_Out";
        this.WMaster.ServerModify = true;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

    #endregion

    #region 默认值绑定

    protected object GetEmployeeId()
    {
        String str = Srvtools.CliUtils.GetValue("_UserCode")[1].ToString();
        str = int.Parse(str).ToString();
        return str;
    }

    protected bool IsDepVisible(string dep)
    {
        return dep != string.Empty;
    }

    protected bool ValidateDateFrom(object value)
    {
        //edit insert 必须名称一致 
        WebDropDownList ddsh = (WebDropDownList)this.WebFormView1.FindControl("WebDropDownList1");
        WebDropDownList ddsm = (WebDropDownList)this.WebFormView1.FindControl("WebDropDownList2");
        WebDropDownList ddeh = (WebDropDownList)this.WebFormView1.FindControl("WebDropDownList3");
        WebDropDownList ddem = (WebDropDownList)this.WebFormView1.FindControl("WebDropDownList4");

        DateTime st = DateTime.Parse(value.ToString() + " " + ddsh.SelectedValue + ":" + ddsm.SelectedValue + ":00");
        DateTime et = DateTime.Parse(value.ToString() + " " + ddeh.SelectedValue + ":" + ddem.SelectedValue + ":00");
        if (st.CompareTo(et) <= 0)
        {
            return true;
        }
        else
        {
            return false;
        }



    }


    #endregion




    protected void WebFormView1_DataBound(object sender, EventArgs e)
    {
        if (WebFormView1.CurrentMode == FormViewMode.Insert || WebFormView1.CurrentMode == FormViewMode.Edit)
        {
            if (Request.Params["MS"] != null)
            {
                WebRefVal tbEmployee = (WebRefVal)this.WebFormView1.FindControl("WebRefVal1");
                if (tbEmployee != null)
                    tbEmployee.ReadOnly = false;
            }
            else
            {
                WebRefVal tbEmployee = (WebRefVal)this.WebFormView1.FindControl("WebRefVal1");
                if (tbEmployee != null)
                    tbEmployee.ReadOnly = true;
            }
        }

    }
    protected void FLWebNavigator1_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "cmdApply")
        {
            if (IsPostBack == true)
            {
                if (Request["id"] != null)
                {
                   // Master.Reload();
                    Master.SetWhere("OutId=" + Request["id"].ToString());
                }
                else
                {
                   // Master.Reload();
                }
            }

        }
    }
}
